//
//  UIImageView+Extension.swift
//  FWSinaWeibo
//
//  Created by 范伟 on 16/2/24.
//  Copyright © 2016年 FanWei. All rights reserved.
//

import UIKit
import SDWebImage

extension UIImageView {
    
    //MARK:使用图片构建图像框
    //增加外部参数，并指定参数前缀，以避与系统方法混淆
    convenience init(fw_imageName imageName: String) {
        self.init(image: UIImage(named: imageName))
    }
    
    func fw_setImageWithURL(urlString: String?, placeholderName: String?) {
        var placeholderImage: UIImage?
        if placeholderName != nil {
            placeholderImage = UIImage(named: placeholderName!)
        }
        guard let urlString = urlString,
            let url = NSURL(string: urlString) else {
                //如果urlString为空或者指定的urlString无法创建有效的URL，显示占位图片
                image = placeholderImage
                return
        }
//        sd_setImageWithURL(url)
        sd_setImageWithURL(url, placeholderImage: placeholderImage)
    }
}
